﻿using MediatR;
using Purchase.ApiS.Dto;
using Purchase.ApiS.ListDisplay.Command;
using Purchase.Domian.Model;
using Purchase.ErrorCode;
using Purchase.Infrastructrue.Implenment;
using SqlSugar;
using System.Text;

namespace Purchase.ApiS.ListDisplay.Hanlder
{
    public class GetSupplierCommandHanlder : IRequestHandler<GetSupplierCommand, ApiResult<SupplierModel>>
    {
        ILogger<GetSupplierCommandHanlder> logger;
        IBaseRepostity<SupplierModel> baseRepostity;
        IBaseRepostity<SupplierGrade> gradeRepostity;

        public GetSupplierCommandHanlder(ILogger<GetSupplierCommandHanlder> logger, IBaseRepostity<SupplierModel> baseRepostity, IBaseRepostity<SupplierGrade> gradeRepostity)
        {
            this.logger = logger;
            this.baseRepostity = baseRepostity;
            this.gradeRepostity = gradeRepostity;
        }
        /// <summary>
        /// 供应商列表展示
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>

        public async Task<ApiResult<SupplierModel>> Handle(GetSupplierCommand request, CancellationToken cancellationToken)
        {
            ApiResult<SupplierModel> result = new ApiResult<SupplierModel>();

            try
            {


                var user = baseRepostity.GetAll().ToList();
                result.Code = ApiEume.Success;
                result.Msg = "获取质检人员的列表成功";
                result.Datas = user;



            }
            catch (Exception ex)
            {
                logger.LogError(ex, "获取供应商展示数据异常日志" + ex.Message);
                throw;
            }
            return result;
           
        }
    }
}
